package com.lims.admin.model;

import javax.persistence.*;

import org.hibernate.annotations.GenericGenerator;

import org.hibernate.validator.constraints.*;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import java.util.*;

import javacommon.base.*;

/**
 * 
 * @author zzh
 * 
 */
@Entity
@Table(name = "T_MENU")
public class Menu extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;

	// alias
	public static final String TABLE_ALIAS = "Menu";
	public static final String ALIAS_OBJID = "ID";
	public static final String ALIAS_MENUNAME = "菜单名称";
	public static final String ALIAS_MENUURL = "URL";
	public static final String ALIAS_PARENTID = "父菜单ID";
	public static final String ALIAS_ISLEAF = "是否为叶子菜单";
	public static final String ALIAS_MENULEVEL = "菜单级别";
	public static final String ALIAS_DISCRIBE = "说明";

	// date formats

	// 可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	// columns START
	/**
	 * ID db_column: OBJID
	 */
	@Length(max = 32)
	private java.lang.String objid;
	/**
	 * 菜单名称 db_column: MENUNAME
	 */
	@Length(max = 100)
	private java.lang.String menuname;
	
	/**
	 * URL db_column: MENUURL
	 */
	@Length(max = 200)
	private java.lang.String menuurl;
	
	/**
	 * 父菜单ID db_column: PARENTID
	 */
	@Length(max = 32)
	private java.lang.String parentid;
	
	/**
	 * 是否为叶子菜单 db_column: ISLEAF
	 */
	private Integer isleaf;

	/**
	 * 菜单级别 db_column: MENULEVEL
	 * 1:父菜单 
	 * 2：叶子菜单
	 * 10：资源
	 * 11
	 */
	private Integer menulevel;
	
	/**
	 * 说明 db_column: DISCRIBE 
	 */
	@Length(max = 200)
	private java.lang.String discribe;
	
	
	private Integer sortno;

	// columns END
	
	public Menu() {
	}

	public Menu(java.lang.String objid) {
		this.objid = objid;
	}

	public void setObjid(java.lang.String value) {
		this.objid = value;
	}

	@Id
	@GeneratedValue(generator = "custom-id")
	@GenericGenerator(name = "custom-id", strategy = "uuid")
	@Column(name = "OBJID", unique = true, nullable = false, insertable = true, updatable = true, length = 32)
	public java.lang.String getObjid() {
		return this.objid;
	}

	@Column(name = "MENUNAME", unique = false, nullable = true, insertable = true, updatable = true, length = 100)
	public java.lang.String getMenuname() {
		return this.menuname;
	}

	public void setMenuname(java.lang.String value) {
		this.menuname = value;
	}

	@Column(name = "MENUURL", unique = false, nullable = true, insertable = true, updatable = true, length = 200)
	public java.lang.String getMenuurl() {
		return this.menuurl;
	}

	public void setMenuurl(java.lang.String value) {
		this.menuurl = value;
	}
	
	/****/
	@Column(name = "PARENTID", unique = false, nullable = true, insertable = true, updatable = true, length = 32)
	public java.lang.String getParentid() {
		return this.parentid;
	}

	public void setParentid(java.lang.String value) {
		this.parentid = value;
	}
	
	@Column(name = "ISLEAF", unique = false, nullable = true, insertable = true, updatable = true, length = 22)
	public Integer getIsleaf() {
		return this.isleaf;
	}

	public void setIsleaf(Integer value) {
		this.isleaf = value;
	}

	@Column(name = "MENULEVEL", unique = false, nullable = true, insertable = true, updatable = true, length = 22)
	public Integer getMenulevel() {
		return this.menulevel;
	}

	public void setMenulevel(Integer value) {
		this.menulevel = value;
	}

	@Column(name = "DISCRIBE", unique = false, nullable = true, insertable = true, updatable = true, length = 200)
	public java.lang.String getDiscribe() {
		return this.discribe;
	}

	public void setDiscribe(java.lang.String value) {
		this.discribe = value;
	}

	private List<Menu> menus = new ArrayList<Menu>(0);

	public void setMenus(List<Menu> menu) {
		this.menus = menu;
	}

	@OneToMany(cascade = {CascadeType.MERGE }, fetch = FetchType.LAZY, mappedBy = "parentMenu")
	public List<Menu> getMenus() {
		return menus;
	}

	private Menu parentMenu;
	
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "PARENTID", nullable = false, insertable = false, updatable = false) })
	public Menu getParentMenu() {
		return parentMenu;
	}

	public void setParentMenu(Menu parentMenu) {
		this.parentMenu = parentMenu;
	}
	
	private List<Role> roles = new ArrayList<Role>(0);
	

	@ManyToMany(mappedBy="menus")
	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
	
	@Column(name="SORTNO",unique = false, nullable = true, insertable = true, updatable = true, length = 2)
	public Integer getSortno() {
		return sortno;
	}

	public void setSortno(Integer sortno) {
		this.sortno = sortno;
	}


	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
				.append("Objid", getObjid()).append("Menuname", getMenuname())
				.append("Menuurl", getMenuurl())
				.append("Parentid", getParentid())
				.append("Isleaf", getIsleaf())
				.append("Menulevel", getMenulevel())
				.append("Discribe", getDiscribe()).toString();
	}

	public int hashCode() {
		return new HashCodeBuilder().append(getObjid()).toHashCode();
	}

	public boolean equals(Object obj) {
		if (obj instanceof Menu == false)
			return false;
		if (this == obj)
			return true;
		Menu other = (Menu) obj;
		return new EqualsBuilder().append(getObjid(), other.getObjid())
				.isEquals();
	}
	
}
